using System;
using System.Collections.Generic;
using System.Windows.Forms;
using EzPos.GUI;
using EzPos.GUIs.Forms;
using EzPos.Model.Common;
using EzPos.Model.SaleOrder;
using EzPos.Model.Table;
using EzPos.Model.Users;
using EzPos.Properties;
using EzPos.Service;
using EzPos.Service.Report;

namespace EzPos
{
    internal static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        private static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            //var frmSplash = new FrmSplash();
            //Application.Run(frmSplash);

            InvoicePrinting();
        }

        private static void InvoicePrinting()
        {
            var commonService = ServiceFactory.GenerateServiceInstance().GenerateCommonService();
            commonService.InitializeGlobalConfiguration();

            var saleOrderService = ServiceFactory.GenerateServiceInstance().GenerateSaleOrderService();
            
            var reportService = new ReportService {SaleOrderService = saleOrderService};
            reportService.SaleStatementReport("29/08/2011", "31/12/2011");

            saleOrderService.SaleOrderManagement(
                new SaleOrder{ CustomerId = 1}, Resources.OperationRequestInsert);

            AppContext.User = new User();
            AppContext.InvoiceFontSize = 15f;
            AppContext.InvoiceFontName = "Khmer OS Metal Chrieng";
            AppContext.IssueReceipt = "True";
            AppContext.UserPermissionList = new List<UserPermission>
                                                {
                                                    new UserPermission
                                                        {
                                                            UserId = 1,
                                                            PermissionId = 30
                                                        }
                                                };

            const int saleOrderId = 622;
            var searchCriteria = new List<string> { "SaleOrderId|" + saleOrderId };

            var saleOrderList = saleOrderService.GetSaleOrders(searchCriteria);
            var saleItemList = saleOrderService.GetSaleItems(saleOrderId);

            //Payment
            using (var frmPayment = new FrmPayment())
            {
                var saleOrder = (SaleOrder) saleOrderList[0];
                frmPayment.DiscountPercentage = saleOrder.Discount;
                frmPayment.Table = new Table();
                frmPayment.SaleOrder = saleOrder;
                frmPayment.SaleItemList = saleItemList;

                frmPayment.ShowDialog();

            }
        }
    }
}